<?php
session_start();
include('conexao.class.php');

if(isset($_POST['login']) && isset($_POST['password'])){
	$login = $_POST['login'];
	$password  = $_POST['password'];
	
	$db = new Conexao();
	$conexao = $db->open();
	
	$result = pg_query($conexao, "select * from users where login = '$login' and password = '$password';");
	$user = pg_fetch_array($result);
	$db->close();
	if($user){
		$_SESSION['usuario'] = $user;
		header('Location: lista.php');
	}
	else{
		$_SESSION['flash'] = 'Usuário e senha não correspondem.';
		header('Location: login.php');
	}
}
else{
	header('Location: login.php');
}
?>